package com.scalar.chiptrack.operations.dataentry.lotscrap.actions;

import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.operations.dataentry.lotscrap.actioncommands.ScrapMaterialActionCommandFactory;
import com.scalar.chiptrack.actioncommands.ActionCommand;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;


public class ScrapMaterialAction extends ChipTrackAction implements SessionKeys
{

    public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
    {

        HashMap errors = new HashMap();
        request.setAttribute( ERROR_MESSAGES, errors );
        ActionForward actionForward = mapping.findForward( "success" );
        String action 				= request.getParameter( "action" ) ;

        try
        {
            ActionCommand scrapMaterialCommand  = null;
            scrapMaterialCommand 	            = ScrapMaterialActionCommandFactory.getActionCommand( action );
            actionForward 			            = scrapMaterialCommand.execute( mapping, form, request, response );
        }
        catch( Exception e )
        {
            errors.put( "Unable to load the Scrap Material Screen" , null );
            actionForward = mapping.findForward( "search" );
        }
        return actionForward;
    }

}
